package com.orderplus.opshop.fetch.sina.weibo;

import org.jsoup.Connection;
import org.jsoup.Jsoup;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JsoupTest {
	public static void main(String[] args) throws IOException {
		Map<String, String> map = new HashMap<>();
		//map.put请根据自己的微博cookie得到
		map.put("_s_tentry", "login.sina.com.cn");
		map.put("Apache", "8590250943507.381.1534758017640");
		map.put("login_sid_t", "0bd4e84c292620e3aed9862b4ad91b1c");
		map.put("SCF", "AnkI-DZbJ8fxr4V7JLMf5lSLqg70WTp3W4W08I4ImQYgJsZI4_K_wK3ga7HMv-Rn3zBvNuDUKeeqWreisfRJ4Hk.");
		map.put("SINAGLOBAL", "1793024353389.4553.1479174837212");
		map.put("SUB", "_2A252fvztDeRhGedK71YZ8SjPzj6IHXVVCmklrDV8PUNbmtBeLULGkW9NIehNIRmSpSekBJygSBwKLlN7g-Dw4Y_p");
		map.put("SUBP", "0033WrSXqPxfM725Ws9jqgMF55529P9D9WWFGdM31H.w2vFcAuWU4Nzw5JpX5K2hUgL.Fo2XShBReKq0SKz2dJLoIEnLxKML12zLB-eLxKML1hnLBo8gCH9ii--fi-2fi-z0i--Ni-2fiKL8");
		map.put("SUHB", "05iMWT8QM7LgFH");
		map.put("ULV", "1534758018626:10:3:1:8590250943507.381.1534758017640:1534586247687");
		map.put("un", "mascothaojun@sina.com");
		map.put("UOR", ",,login.sina.com.cn");
		map.put("TC-Page-G0", "046bedba5b296357210631460a5bf1d2");
//		map.put("TC-Ugrow-G0","e66b2e50a7e7f417f6cc12eec600f517");
//		map.put("TC-V5-G0","b8dff68fa0e04b3c8f0ba710d783479a");
		map.put("wb_bub_find", "1");
		map.put("wb_bub_find_3459285440", "1");
		map.put("wb_bub_find_5601838195", "1");
		map.put("WBStorage", "2c466cc84b6dda21|undefined");

		Connection.Response res = Jsoup.connect("https://d.weibo.com/102803?ssl_rnd=1534758103.9718")
				.cookies(map).method(Connection.Method.GET).execute();
		String s = res.body();
		System.out.println(s);
		String[] ss = s.split("<script>FM.view");
		int i = 0;
		// pl_content_homeFeed
		// pl.content.homeFeed.index
		List<String> list = new ArrayList<>();
		for (String x : ss) {
//          System.out.println(i++ + "======================================");
//          System.out.println(x.substring(0,
//                  x.length() > 200 ? 200 : x.length()));
//          System.out.println("===========================================");
			if (x.contains("\"html\":\"")) {
				String value = getHtml(x);
				list.add(value);
				System.out.println(value);
			}

		}
		// content=ss[8].split("\"html\":\"")[1].replaceAll("(\\\\t|\\\\n)",
		// "").replaceAll("\\\\\"", "\"").replaceAll("\\\\/", "/");
		// content=content.substring(0,
		// content.length()<=13?content.length():content.length()-13);
		// System.out.println(Native2AsciiUtils.ascii2Native(content));
	}

	public static String getHtml(String s) {
		String content = s.split("\"html\":\"")[1]
				.replaceAll("(\\\\t|\\\\n|\\\\r)", "").replaceAll("\\\\\"", "\"")
				.replaceAll("\\\\/", "/");
		content = content.substring(0,
				content.length() <= 13 ? content.length()
						: content.length() - 13);
		return Native2AsciiUtils.ascii2Native(content);
	}
}
